﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GogTasks.UserControls;
using Business;

namespace GogTasks
{
    public partial class SettingsForm : Form
    {
        SettingsUserControl _settingsControl;
        string _usernameBefore;

        public bool CredentialsChanged = false;

        public SettingsForm()
        {
            InitializeComponent();
            _usernameBefore = MobileContext.Config.Username;
            var su = new SettingsUserControl(this);
            su.Width = smoothListbox1.Width;
            smoothListbox1.AddControl(su);
            _settingsControl = su;
        }

        private void DoneMenuItem_Click(object sender, EventArgs e)
        {
            Done();
            Close();
        }

        private void SettingsForm_Validated(object sender, EventArgs e)
        {

        }

        private void SettingsForm_Closing(object sender, CancelEventArgs e)
        {
            if (!DoneMenuItem.Enabled) e.Cancel = true;
            else Done();
        }

        private void Done()
        {
            MobileContext.Config.Save();
            if (MobileContext.Config.Username != _usernameBefore) CredentialsChanged = true;
            TasksWiped = _settingsControl.TasksWiped;
        }

        public bool TasksWiped;

        internal void EnableButtons(bool enable)
        {
            DoneMenuItem.Enabled = enable;
        }
    }
}